import 'package:flutter/services.dart';
import 'package:flutter_app/utils/log_util.dart';
import 'package:get/get.dart';

///author: create by SunJH
///时间: 2021/12/17 0017
///邮箱: 965989158@qq.com
///描述: 与原生通讯的控制器
///

class CounterNativeConnect extends GetxController{
  var channel = const MethodChannel('com.flutterApp.MethodChannel');
  var fromNativeData = "".obs;
  var printInfoResult = "".obs;

  @override
  void onInit() {
    nativeCallFlutter();
  }

  sendMessageToAndroid(String message){
    channel.invokeMethod('sendData',{'name':'SunJH','age':20,'info':message}).then((value){
      LogUtil.logI(value);
      fromNativeData.value = value.toString();
    });
  }

  nativePrintInfo( ){
    channel.invokeMethod('callFlutter',).then((value){
      LogUtil.logI(value);
      printInfoResult.value = value.toString();
    });
  }

  nativeCallFlutter(){
    channel.setMethodCallHandler((call)async{
      switch(call.method){
        case "flutterMethod":
          print("methodChannelTest 原生Android调用了flutterMethod方法 参数是${call.arguments}");
          return "这是flutter的回复";
      }
    });
  }
}